package com.gradle.tasks

import com.gradle.po.User
import org.gradle.api.DefaultTask
import org.gradle.api.GradleException
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.TaskAction

class AppInfo extends DefaultTask {

    @Input
    String username

    @TaskAction
    void start() {
        println "AppInfo start into"
        withExceptionHanding {
            println "username:${getUsername()}"
            logger.quiet("username:${getUsername()}")
        }
    }

    private void withExceptionHanding(Closure closure) {
        try {
            closure()
        }
        catch (Exception e) {
            logger.error "Failed to execute AppInfo task", e
            throw new GradleException(e.message)
        }
    }
}
